OPENWRT = 0
APPFILE = 1

ifeq ($(OPENWRT), 1)
	CC = ~/OpenWrt-SDK-ar71xx-for-linux-i486-gcc-4.6-linaro_uClibc-0.9.33.2/staging_dir/toolchain-mips_r2_gcc-4.6-linaro_uClibc-0.9.33.2/bin/mips-openwrt-linux-gcc
	#CFLAGS += -I ~/openwrt/trunk/staging_dir/target-mips_r2_uClibc-0.9.33.2/usr/include -L ~/openwrt/trunk/staging_dir/target-mips_r2_uClibc-0.9.33.2/usr/lib
	CFLAGS += -I ~/openwrt-lib/include -L ~/openwrt-lib/lib
	LFLAGS += -lcurl -lcrypto -lz -lssl
	DEFS = -D___LITTLE_ENDIAN

else
	CC = gcc
	LFLAGS += -lcurl
endif

CFLAGS += -Wall -O2
#CFLAGS += -g

LIB_DIR = ./lib
UTIL_DIR = ./util
CORE_DIR = ./core

SRCS += $(LIB_DIR)/md5.c $(LIB_DIR)/base64.c $(LIB_DIR)/hmac_sha1.c
SRCS += $(UTIL_DIR)/oss_time.c $(UTIL_DIR)/oss_common.c $(UTIL_DIR)/oss_map.c $(UTIL_DIR)/oss_auth.c $(UTIL_DIR)/oss_ttxml.c
SRCS += $(CORE_DIR)/oss_client.c $(CORE_DIR)/oss_helper.c $(CORE_DIR)/oss_object_metadata.c $(CORE_DIR)/oss_get_object_request.c $(CORE_DIR)/oss_put_object_result.c $(CORE_DIR)/oss_curl_callback.c
SRCS += $(CORE_DIR)/client_object_operation.c

#可执行文件名和相关的obj文件
ifeq ($(APPFILE), 1)
	APP_BINARY = oss_download_file
	SRCS += oss_download_file.c
	#APP_BINARY = hello_sha1
	#SRCS += hello_sha1.c

else
	APP_BINARY = oss_upload_file
	SRCS += oss_upload_file.c
endif

all: APP_FILE

OBJS = $(SRCS:.c=.o)
APP_FILE: $(OBJS)
	$(CC) $(CFLAGS) $(OBJS) -o $(APP_BINARY) $(LFLAGS)

.PHONY: clean
clean:
	@echo "cleanning project"
	$(RM) *.a $(OBJS) *~ *.so *.lo $(APP_BINARY)
	@echo "clean completed"
